package com.cyloer.smartThread;

import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.fibers.SuspendExecution;
import co.paralleluniverse.fibers.Suspendable;
import co.paralleluniverse.strands.SuspendableRunnable;

import java.util.concurrent.ExecutionException;

/**
 * @Description:
 * @author: xiangliu5
 * @date: 2021/1/12 10:14
 */
public class TestMain {

    public static void main(String[] args) {

        long startTime=System.currentTimeMillis();
        int count =10000;
        Fiber<Void>[] fibers =new Fiber[count];
        for(int i=0;i<fibers.length;i++){
            fibers[i]=new Fiber<Void>(new SuspendableRunnable() {
                @Override
                public void run() throws SuspendExecution, InterruptedException {
                    calc();
                }
            });
        }


        for(int i=0;i<fibers.length;i++){
            fibers[i].start();
        }
        for(int i=0;i<fibers.length;i++){
            try {
                fibers[i].join();
            } catch (ExecutionException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
       calc();

        long endTime=System.currentTimeMillis()-startTime;
        System.out.println("计算耗时:"+endTime);


    }

    public  static void  calc(){
        int result = 0;
        for (int m = 0; m < 100000; m++) {
            for (int i = 0; i < 2000; i++) {
                result += i;
            }
        }
    }
}
